<?php

namespace Ecom\ProdutosBundle\Admin;

/**
 * Description of ProdutoAdmin
 *
 * @author yuri
 */
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Knp\Menu\ItemInterface as MenuItemInterface;
use Sonata\AdminBundle\Route\RouteCollection;

class ProdutoAdmin extends Admin {

    protected function configureRoutes(RouteCollection $collection) {
        $collection->add('addAtributoEdit', $this->getRouterIdParameter() . '/addatributoedit');
        $collection->add('addAtributoCreate', 'addaatributocreate');
        $collection->add('addModeloEdit', $this->getRouterIdParameter() . '/addmodeloedit');
        $collection->add('addModeloCreate', 'addmodelocreate');
    }

    /**
     * @param \Sonata\AdminBundle\Show\ShowMapper $showMapper
     *
     * @return void
     */
    protected function configureShowField(ShowMapper $showMapper) {
        $showMapper
                ->add('nome')
                ->add('descricao')
                ->add('preco')
                ->add('quantidade')
                ->add('categoria')
                ->add('atributo', null, array('required' => false))
        ;
    }

    /**
     * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
     *
     * @return void
     */
    protected function configureFormFields(FormMapper $formMapper) {
        
        $formMapper
                ->add('nome')
                ->add('descricao')
                ->add('preco')
                ->add('quantidade')
                ->add('categoria', 'sonata_type_model')
                ->add('modelo', 'entity', array(
                                         'class' => 'ProdutosBundle:ModeloAtr',
                                         'empty_value' => '-- Modelo de Atributos --', 'required' => false))
                
                ->add('atributo', 'shtumi_ajax_autocomplete', array('entity_alias'=>'atributos', 'required' => false));
        ;
    }

    /**
     * @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
     *
     * @return void
     */
    protected function configureListFields(ListMapper $listMapper) {
        $listMapper
                ->addIdentifier('nome')
                ->add('preco')
                ->add('quantidade')
                ->add('categoria')
                ->add('_action', 'actions', array(
                    'actions' => array(
                        'view' => array(),
                        'edit' => array(),
                        'delete' => array(),
                    )
                ))
        ;
    }

    /**
     * @param \Sonata\AdminBundle\Datagrid\DatagridMapper $datagridMapper
     *
     * @return void
     */
    protected function configureDatagridFilters(DatagridMapper $datagridMapper) {
        $datagridMapper
                ->add('nome')
                ->add('preco')
                ->add('quantidade')
                ->add('categoria')
        //->add('atributo', null, array('required'=>false))
        ;
    }

}

?>